package com.gewei.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * 分页查询条件封装对象
 */
@Data
public class QueryPageBean implements Serializable {

    private static final long serialVersionUID = -6084719893215077076L;
    private static final Integer DEFAULT_CURRENT_PAGE = 1;
    private static final Integer DEFAULT_PAGE_SIZE = 10;
    private static final Integer MAX_PAGE_SIZE = 100;

    /**
     * 当前页码
     */
    private Integer currentPage;

    /**
     * 每页显示记录数
     */
    private Integer pageSize;

    /**
     * 查询条件
     */
    private String queryString;

    /**
     * 参数检查
     */
    public void checkParam() {
        if (this.currentPage == null || this.currentPage < 1) {
            //  页码通常从 1 开始
            setCurrentPage(DEFAULT_CURRENT_PAGE);
        }
        if (this.pageSize == null || this.pageSize < 1 || this.pageSize > MAX_PAGE_SIZE) {
            setPageSize(DEFAULT_PAGE_SIZE);
        }
        if (this.queryString == null) {
            //  或根据业务设为默认搜索条件
            setQueryString("");
        }
        setQueryString(queryString.trim());
    }
}